package com.hs.wa.service;

import com.hs.wa.dao.UserMapper;
import com.hs.wa.entity.User;
import com.hs.wa.entity.UserCondition;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;
    @Resource

    private JdbcTemplate jdbcTemplate;


    public boolean addUser(User user) {
        boolean flag = false;
        if (!!(userMapper.insert(user) > 0)) {
            flag = true;
        }
        return flag;
    }

    public boolean selectUser(User user) {


        String sql = "select username from User where username='" + user.getUsername() + "' and password='" + user.getPassword() + "'";

        Map<String, Object> map = jdbcTemplate.queryForMap(sql);
        Object username = map.get("username");
        if ("".equals(username)) {
            return false;
        }
        System.out.println(username);
        return true;
    }
}
